using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class GUI_Webpage_ChangePassword : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtUserID.Text = Session["user"].ToString();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        DeleteBlank();
    }

    private void DeleteBlank()
    {
        txtPassword.Text = "";
        txtNewPass.Text = "";
        txtReNewPass.Text = "";
    }
        protected void btnOK_Click(object sender, EventArgs e)
    {
        UserInfo userInfo = new UserInfo();
        UserBll userBll = new UserBll();

        userInfo.UserID = txtUserID.Text;
        userInfo.Password = txtPassword.Text;
        string newPass = txtNewPass.Text;
        string reNewPass = txtReNewPass.Text;

        if (newPass == reNewPass) 
        {
            if (userBll.CheckUserPass(userInfo) > 0)
            {
                userInfo.Password = newPass;
                userBll.UpdateUser(userInfo);
                DeleteBlank();

                if (Int32.Parse(Session["role"].ToString()) == 0)
                {
                    Response.Redirect("Admin/UserManagement.aspx");
                }
                else
                    if (Int32.Parse(Session["role"].ToString()) == 1)
                    {
                        Response.Redirect("Manager/ManageBooking.aspx");
                    }
            }            
        }
            
    }
}
